package com.sailfish.springbootdemo.dao.db2;

import com.sailfish.springbootdemo.common.DB2TableName;
import com.sailfish.springbootdemo.pojo.db2.PcbNewTechnologyInfo;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

import java.util.List;

public interface PcbNewTechnologyInfoDao {
    @Results(id = "pcbNewTechnologyInfoResultMap", value = {
            @Result(column = "pcb_new_technology_info_id", property = "pcbNewTechnologyInfoId", jdbcType = JdbcType.INTEGER),
            @Result(column = "proposed_time", property = "proposedTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "pcb_technology_desc", property = "pcbTechnologyDesc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_technology_advantage", property = "pcbTechnologyAdvantage", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_technology_dev_status", property = "pcbTechnologyDevStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pic_desc", property = "picDesc", jdbcType = JdbcType.VARCHAR),
            @Result(column = "value_analysis", property = "valueAnalysis", jdbcType = JdbcType.VARCHAR),
            @Result(column = "pcb_technology_status", property = "pcbTechnologyStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "responsibility_user_id", property = "responsibilityUserId", jdbcType = JdbcType.INTEGER),
            @Result(column = "responsibility_user_name", property = "responsibilityUserName", jdbcType = JdbcType.VARCHAR),
            @Result(column = "remark", property = "remark", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_status", property = "approveStatus", jdbcType = JdbcType.VARCHAR),
            @Result(column = "approve_user_id", property = "approveUserId", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_time", property = "createTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "update_time", property = "updateTime", jdbcType = JdbcType.DATETIMEOFFSET),
            @Result(column = "status", property = "status", jdbcType = JdbcType.INTEGER),
            @Result(column = "sort", property = "sort", jdbcType = JdbcType.INTEGER),
            @Result(column = "create_user", property = "createUser", jdbcType = JdbcType.VARCHAR),
            @Result(column = "update_user", property = "updateUser", jdbcType = JdbcType.VARCHAR),
    })

    /*
     * 单个查询
     */
    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_NEW_TECHNOLOGY_INFO +
            " where 1 = 1 " +
            "<if test='id != null'>" +
            " and pcb_new_technology_info_id = #{id}" +
            "</if>" +
            " order by sort" +
            "</script>")
    PcbNewTechnologyInfo getAllById(@Param("id") Integer id);

    /*
     * 查询指定行数据
     */
    @Select("<script> " +
            "select *" +
            " from " + DB2TableName.PCB_NEW_TECHNOLOGY_INFO +
            " where 1 = 1 " +
            "<if test='search != null'>" +
            " and ( proposed_time like concat('%',#{search},'%') " +
            " or pcb_technology_desc like concat('%', #{search},'%') " +
            " or pcb_technology_advantage like concat('%', #{search},'%') " +
            " or pcb_technology_dev_status like concat('%', #{search},'%') " +
            " or value_analysis like concat('%', #{search},'%') " +
            " or pcb_technology_status like concat('%', #{search},'%') )" +
            "</if>" +
            "<if test='responsibilityUserId != null '>" +
            " and responsibility_user_id = #{responsibilityUserId}" +
            "</if>" +
            "<if test='approveStatus != null '>" +
            " and approve_status = #{approveStatus}" +
            "</if>" +
            "<if test='approveUserId != null '>" +
            " and approve_user_id = #{approveUserId}" +
            "</if>" +
            "<if test='responsibilityUserName != null '>" +
            " and responsibility_user_name = #{responsibilityUserName} " +
            "</if>" +
            " order by sort" +
            "<if test='begin != null and pageSize != null and pageSize != \"\" '>" +
            " limit #{begin}, #{pageSize}" +
            "</if>" +
            "</script>")
    @ResultMap(value = "pcbNewTechnologyInfoResultMap")
    List<PcbNewTechnologyInfo> getAllByLimit(@Param("search") String search, @Param("approveStatus") String approveStatus, @Param("approveUserId") Integer approveUserId,
                                             @Param("responsibilityUserId") Integer responsibilityUserId, @Param("responsibilityUserName") String responsibilityUserName,
                                             @Param("begin") Integer begin, @Param("pageSize") Integer pageSize);

    /*
     *新增所有列
     */
    @Insert("insert into " + DB2TableName.PCB_NEW_TECHNOLOGY_INFO + " (proposed_time, pcb_technology_desc, pcb_technology_advantage, pcb_technology_dev_status, pic_desc, value_analysis, pcb_technology_status, responsibility_user_id, responsibility_user_name, remark, approve_status, approve_user_id, create_time, create_user, update_time, update_user, status, sort) values " +
            "(#{proposedTime}, #{pcbTechnologyDesc}, #{pcbTechnologyAdvantage}, #{pcbTechnologyDevStatus}, #{picDesc}, #{valueAnalysis}, #{pcbTechnologyStatus}, #{responsibilityUserId}, #{responsibilityUserName}, #{remark}, #{approveStatus}, #{approveUserId}, #{createTime}, #{createUser}, #{updateTime}, #{updateUser}, #{status}, #{sort})")
    // 显式设置主键
    @Options(useGeneratedKeys = true, keyProperty = "pcbNewTechnologyInfoId")
    Integer insert(PcbNewTechnologyInfo param);

    /*
     *通过主键删除
     */
    @Delete("delete from " + DB2TableName.PCB_NEW_TECHNOLOGY_INFO + " where pcb_new_technology_info_id = #{id} ")
    Integer delete(@Param("id") Integer id);

    /*
     *通过主键修改数据
     */
    @Update("<script>" +
            "update " + DB2TableName.PCB_NEW_TECHNOLOGY_INFO +
            "<set> " +
            "<if test='proposedTime != null'>" +
            " proposed_time = #{proposedTime}," +
            "</if>" +
            "<if test='pcbTechnologyDesc != null'>" +
            " pcb_technology_desc = #{pcbTechnologyDesc}," +
            "</if>" +
            "<if test='pcbTechnologyAdvantage != null'>" +
            " pcb_technology_advantage = #{pcbTechnologyAdvantage}," +
            "</if>" +
            "<if test='pcbTechnologyDevStatus != null'>" +
            " pcb_technology_dev_status = #{pcbTechnologyDevStatus}," +
            "</if>" +
            "<if test='picDesc != null'>" +
            " pic_desc = #{picDesc}," +
            "</if>" +
            "<if test='valueAnalysis != null'>" +
            " value_analysis = #{valueAnalysis}," +
            "</if>" +
            "<if test='pcbTechnologyStatus != null'>" +
            " pcb_technology_status = #{pcbTechnologyStatus}," +
            "</if>" +
            "<if test='responsibilityUserId != null'>" +
            " responsibility_user_id = #{responsibilityUserId}," +
            "</if>" +
            "<if test='responsibilityUserName != null'>" +
            " responsibility_user_name = #{responsibilityUserName}," +
            "</if>" +
            "<if test='remark != null and remark != \"\"'>" +
            "remark = #{remark}," +
            "</if>" +
            "<if test='approveStatus != null and approveStatus != \"\"'>" +
            "approve_status = #{approveStatus}," +
            "</if>" +
            "<if test='approveUserId != null and approveUserId != \"\"'>" +
            "approve_user_id = #{approveUserId}," +
            "</if>" +
            "<if test='createUser != null and createUser != \"\"'>" +
            "create_user = #{createUser}," +
            "</if>" +
            "<if test='createTime != null '>" +
            "create_time = #{createTime}," +
            "</if>" +
            "<if test='updateUser != null and updateUser != \"\"'>" +
            "update_user =#{updateUser}," +
            "</if>" +
            "<if test='updateTime != null '>" +
            "update_time = #{updateTime}," +
            "</if>" +
            "<if test='status != null '>" +
            "status = #{status}," +
            "</if>" +
            "<if test='sort != null '>" +
            "sort = #{sort} " +
            "</if>" +
            "</set> " +
            "where pcb_new_technology_info_id = #{pcbNewTechnologyInfoId}" +
            "</script>")
    Integer update(PcbNewTechnologyInfo param);
}
